<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Retrieve the default stream context</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.stream-context-create.html">stream_context_create</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.stream-context-get-options.html">stream_context_get_options</a></div>
 <div class="up"><a href="ref.stream.html">Stream 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.stream-context-get-default" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">stream_context_get_default</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.1.0)</p><p class="refpurpose"><span class="refname">stream_context_get_default</span> &mdash; <span class="dc-title">Retrieve the default stream context</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.stream-context-get-default-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">resource</span> <span class="methodname"><strong>stream_context_get_default</strong></span>
    ([ <span class="methodparam"><span class="type">array</span> <code class="parameter">$options</code></span>
  ] )</div>

  <p class="simpara">
   Returns the default stream context which is used whenever file operations
   (<span class="function"><a href="function.fopen.html" class="function">fopen()</a></span>, <span class="function"><a href="function.file-get-contents.html" class="function">file_get_contents()</a></span>, etc...)
   are called without a context parameter.  Options for the default context
   can optionally be specified with this function using the same syntax as
   <span class="function"><a href="function.stream-context-create.html" class="function">stream_context_create()</a></span>.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.stream-context-get-default-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<em><code class="parameter">options</code></em></dt>

     <dd>

      <span class="simpara">
       <em><code class="parameter">options</code></em> must be an associative
       array of associative arrays in the format
       <em>$arr[&#039;wrapper&#039;][&#039;option&#039;] = $value</em>.
      </span>
      <blockquote class="note"><p><strong class="note">Note</strong>: 
       <p class="para">
        As of PHP 5.3.0, the <span class="function"><a href="function.stream-context-set-default.html" class="function">stream_context_set_default()</a></span> function
        can be used to set the default context.
       </p>
      </p></blockquote>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.stream-context-get-default-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   A stream context <span class="type"><a href="language.types.resource.html" class="type resource">resource</a></span>.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.stream-context-get-default-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="stream-context-get-default.example.basic">
    <p><strong>Example #1 Using <span class="function"><strong>stream_context_get_default()</strong></span></strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$default_opts&nbsp;</span><span style="color: #007700">=&nbsp;array(<br />&nbsp;&nbsp;</span><span style="color: #DD0000">'http'</span><span style="color: #007700">=&gt;array(<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'method'</span><span style="color: #007700">=&gt;</span><span style="color: #DD0000">"GET"</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'header'</span><span style="color: #007700">=&gt;</span><span style="color: #DD0000">"Accept-language:&nbsp;en\r\n"&nbsp;</span><span style="color: #007700">.<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"Cookie:&nbsp;foo=bar"</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'proxy'</span><span style="color: #007700">=&gt;</span><span style="color: #DD0000">"tcp://10.54.1.39:8000"<br />&nbsp;&nbsp;</span><span style="color: #007700">)<br />);<br /><br /><br /></span><span style="color: #0000BB">$alternate_opts&nbsp;</span><span style="color: #007700">=&nbsp;array(<br />&nbsp;&nbsp;</span><span style="color: #DD0000">'http'</span><span style="color: #007700">=&gt;array(<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'method'</span><span style="color: #007700">=&gt;</span><span style="color: #DD0000">"POST"</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'header'</span><span style="color: #007700">=&gt;</span><span style="color: #DD0000">"Content-type:&nbsp;application/x-www-form-urlencoded\r\n"&nbsp;</span><span style="color: #007700">.<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"Content-length:&nbsp;"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">strlen</span><span style="color: #007700">(</span><span style="color: #DD0000">"baz=bomb"</span><span style="color: #007700">),<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'content'</span><span style="color: #007700">=&gt;</span><span style="color: #DD0000">"baz=bomb"<br />&nbsp;&nbsp;</span><span style="color: #007700">)<br />);<br /><br /></span><span style="color: #0000BB">$default&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">stream_context_get_default</span><span style="color: #007700">(</span><span style="color: #0000BB">$default_opts</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$alternate&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">stream_context_create</span><span style="color: #007700">(</span><span style="color: #0000BB">$alternate_opts</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;Sends&nbsp;a&nbsp;regular&nbsp;GET&nbsp;request&nbsp;to&nbsp;proxy&nbsp;server&nbsp;at&nbsp;10.54.1.39<br />&nbsp;*&nbsp;For&nbsp;www.example.com&nbsp;using&nbsp;context&nbsp;options&nbsp;specified&nbsp;in&nbsp;$default_opts<br />&nbsp;*/<br /></span><span style="color: #0000BB">readfile</span><span style="color: #007700">(</span><span style="color: #DD0000">'http://www.example.com'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;Sends&nbsp;a&nbsp;POST&nbsp;request&nbsp;directly&nbsp;to&nbsp;www.example.com<br />&nbsp;*&nbsp;Using&nbsp;context&nbsp;options&nbsp;specified&nbsp;in&nbsp;$alternate_opts<br />&nbsp;*/<br /></span><span style="color: #0000BB">readfile</span><span style="color: #007700">(</span><span style="color: #DD0000">'http://www.example.com'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">false</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$alternate</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.stream-context-get-default-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.stream-context-create.html" class="function" rel="rdfs-seeAlso">stream_context_create()</a> - Creates a stream context</span></li>
    <li class="member">Listing of supported wrappers with context options (<a href="wrappers.html" class="xref">支持的协议和封装协议</a>).</li>
   </ul>
  </p>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.stream-context-create.html">stream_context_create</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.stream-context-get-options.html">stream_context_get_options</a></div>
 <div class="up"><a href="ref.stream.html">Stream 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
